import fetch from '../config/fetch';
import {baseUrl} from '../config/env';
import { getStore } from '../config/mUtils'

/**
 * 获取验证码
 * captcha_type: 'both' / 'login' / ''
 */
export const getLoginCode = () => {
  // return baseUrl + '/organization/v1/getVerify';
  return baseUrl + '/organization/v1/getVerify?time=' + Math.random()*1;
}


/**
 * 注册
 * @param {
  "captcha": "string",
  "email": "string",
  "infoName": "string",
  "inviteCode": "string",
  "password": "string",
  "phone": "string"
} 
 */
export const register = (data) => fetch({
  url: '/organization/v1/register',
  method: "post",
  data: data,
  isLogin: true
});

/**
 * 登录
 * {
  "captcha": "string",
  "password": "string",
  "userName": "string"
}
 */
export const login = (data) => fetch({
  url: '/web/login/v1/login',
  method: "post",
  data: data,
  isLogin: true
});

/**
 * 发送验证码
 */
export const getCode = (phone) => fetch({
  url: '/organization/v1/' + phone + '/sendCaptcha',
  method: "get",
  data: {},
  isLogin: true
});

/**
 * 检测企业名称是否唯一
 */
export const checkEnterpriceName = (orgName) => fetch({
  url: '/organization/v1/isExistOrgName',
  method: "get",
  data: {orgName: orgName},
  isLogin: true
});
 
/**
 * 检测企业名称是否唯一
 */
export const checkPhone = (phone) => fetch({
  url: '/organization/v1/' + phone + '/isExistPhone',
  method: "get",
  data: {},
  isLogin: true
});

/**
 * 验证验证码
 * {
  "captcha": "string",
  "password": "string",
  "userName": "string"
}
 */
export const checkCode = (phone, captcha) => fetch({
  url: '/wxuser/v1/checkPhoneCaptcha',
  method: "get",
  data:  {"phone":phone,"captcha": captcha},
  isLogin: true
});
